import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { AjaxResult } from '@/api/model';
import { PageRequest, PageData } from '@/utils/common/types';
import { InputDto, OutputDto } from './materialoutstorage.data';

enum Api {
  Read = '/api/admin/materialoutstorage/read',
  Create = '/api/admin/materialoutstorage/create',
  Update = '/api/admin/materialoutstorage/update',
  Delete = '/api/admin/materialoutstorage/delete',
  ApplyToRd = '/api/admin/materialoutstorage/applytord',
  ApplyRdToComplete = '/api/admin/materialoutstorage/applyrdtocomplete',
  RdToApply = '/api/admin/materialoutstorage/rdtoapply',
}

export function Read(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<OutputDto>>(
    {
      url: Api.Read,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function Create(dto: InputDto, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Create,
      params: dto,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function Update(dto: InputDto, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Update,
      params: dto,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function Delete(id: string, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Delete,
      params: { id },
    },
    {
      joinParamsToUrl: true,
      errorMessageMode: mode,
    },
  );
}

export function ApplyToRd(id: string, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.ApplyToRd,
      params: { id },
    },
    {
      joinParamsToUrl: true,
      errorMessageMode: mode,
    },
  );
}

export function ApplyRdToComplete(id: string, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.ApplyRdToComplete,
      params: { id },
    },
    {
      joinParamsToUrl: true,
      errorMessageMode: mode,
    },
  );
}

export function RdToApply(id: string, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.RdToApply,
      params: { id },
    },
    {
      joinParamsToUrl: true,
      errorMessageMode: mode,
    },
  );
}
